package com.seek.quartz;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.seek.cache.CacheUtil;
import com.seek.service.ReadService;
import com.seek.util.ConstantsUtil;
import com.seek.util.JsonUtil;

/**
 * 数据迁移处理
 * @author lushuangteng
 *
 */
public class TodayCountRefreshQuartz {
	private static Logger logger = LoggerFactory.getLogger(DataBakQuartz.class);
	@Resource
	private ReadService readService;

	public void run(){
		try{
			StringBuffer sb = new StringBuffer("select (select count(1) from t_customer_certify where audit_status=0 and company_id=?) verifyNum,");
			sb.append("(select count(1) from t_customer_zfb where audit_status=0 and lsbz=0 and company_id=?) zfbVerifyNum,")
			.append("(select count(1) from t_loan where loan_status=0 and company_id=?) loanAuditNum,")
			.append("(select count(1) from t_loan where loan_status in (3,6) and end_time<now() and company_id=?) overdueNum,")
			.append("(select count(1) from t_customer_certify where audit_status=1 and audit_time>curdate() and company_id=?) certifyUserToday,")
			.append("(select count(1) from t_loan where req_date>curdate() and company_id=?) loanNumToday,")
			.append("(select ifnull(sum(req_money),0) from t_loan where req_date>curdate() and company_id=?) loanMoneyToday from dual");
			Long companyId = ConstantsUtil.COMPANYID;
			Map<String,Object> m = readService.findOneMapBySql(sb.toString(), new Object[]{companyId,companyId,companyId,companyId,companyId,companyId,companyId});
			CacheUtil.putRedisData("TODAYCOUNT_CACHE_"+companyId, JsonUtil.toJson(m));
		}catch(Exception e){
			logger.error(e.getMessage());
		}
	}
}
